package edu.ycu.aladdin.collector;

import edu.ycu.aladdin.collector.utils.HttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.Test;

import java.io.IOException;

@Slf4j
public class ElementalHttpGet {

    String url = "https://m.weibo.cn/api/container/getIndex?type=uid&value=1926909715";
    @Test
    public void getTest(){
        try {
            String s = HttpUtils.get(url);
            log.info("res:{}",s);
        } catch (IOException e) {
            log.error("HttpUtils.get({}) exception:{}",url,e);
        }
    }
    @Test
    public void demo(){
        try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
            HttpGet httpGet = new HttpGet(url);

            try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
                System.out.println(response.getStatusLine());
                HttpEntity entity = response.getEntity();
                log.info(EntityUtils.toString(entity));
            }

        } catch (IOException e) {
            log.warn("HttpUtils.get({}) exception:{}",url,e);
        }
    }

}